package com.mi.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.mi.bean.Customers;
import com.mi.bean.Goods;
import com.mi.bean.Manager;
import com.mi.service.impl.AjaxServiceToDelGoodsImpl;
import com.mi.service.impl.AjaxServiceToDelUsersImpl;
import com.mi.service.impl.AjaxServiceToDeletManagerImpl;
import com.mi.service.impl.AjaxServiceToUsersImpl;
import com.mi.utils.MyUtils;

/**
 * ajax查询后台业务逻辑处理
 */
@WebServlet("/AjaxProjectsMessageDeleteAction")
public class AjaxProjectsMessageDeleteAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 进行ajax响应
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 接收数据，将数据映射为实体类
		Goods goodsB=MyUtils.convertFormData2Bean(request, Goods.class);
		//进行查询操作
		int i=MyUtils.getInstance(AjaxServiceToDelGoodsImpl.class).saveOrUpdateAdminInf(goodsB);
//				if(i > 0) {
//					// 删除成功
//					Customers customersA1=MyUtils.convertFormData2Bean(request, Customers.class);
//					List<Customers> lstCustomers=MyUtils.getInstance(AjaxServiceToUsersImpl.class).queryLoginInfoByParams(customersA1);
//					System.out.println("从客户端请求获取的用户信息为："+lstCustomers);
//					//借助第三方的工具将集合转换为json字符串【阿里巴巴的fastjson插件包】
//					//将查询结果集list转换为json字符串
//					String strJson=JSON.toJSONStringWithDateFormat(lstCustomers, "yyyy-MM-dd HH:mm:ss");
//					//ajax响应
//					//响应客户端的请求
		if(i>0) {
					PrintWriter pw=response.getWriter();
					pw.write(i);
					pw.flush();
					
					pw.close();
		}else {
			request.getRequestDispatcher("WEB-INF/logined/adminManage/QueryManagers.jsp").forward(request, response);
		}
					//request.getRequestDispatcher("WEB-INF/logined/adminManage/jumpweb.jsp").forward(request, response);
			// request.getRequestDispatcher("WEB-INF/login.jsp").forward(request, response);
					
//				}
				//else {
					// 保存失败
					//request.getRequestDispatcher("WEB-INF/register.jsp").forward(request, response);
				//}
	}

}
